#!/bin/sh

uci -q batch <<-EOF >/dev/null
	delete ucitrack.@smartvpn[-1]
	add ucitrack smartvpn
	set ucitrack.@smartvpn[-1].init=smartvpn
	commit ucitrack
EOF

# update system default domain setting(this step is importance for update installation)
cp -p /usr/share/smartvpn/proxy/proxy_mainland.txt /etc/smartvpn/proxy_mainland.txt
cp -p /usr/share/smartvpn/proxy/proxy_hongkong.txt /etc/smartvpn/proxy_hongkong.txt
cp -p /usr/share/smartvpn/proxy/proxy_oversea.txt /etc/smartvpn/proxy_oversea.txt

# update system backup config for recovery after factory reset
grep -qxF '/etc/smartvpn' /etc/sysupgrade.conf || echo '/etc/smartvpn' >> /etc/sysupgrade.conf
grep -qxF '/usr/share/smartvpn/conf' /etc/sysupgrade.conf || echo '/usr/share/smartvpn/conf' >> /etc/sysupgrade.conf
grep -qxF '/usr/share/smartvpn/service' /etc/sysupgrade.conf || echo '/usr/share/smartvpn/service' >> /etc/sysupgrade.conf
grep -qxF '/usr/libexec/softethervpn/vpn_server.config' /etc/sysupgrade.conf || echo '/usr/libexec/softethervpn/vpn_server.config' >> /etc/sysupgrade.conf
grep -qxF '/opt/rrd' /etc/sysupgrade.conf || echo '/opt/rrd' >> /etc/sysupgrade.conf
grep -qxF '/opt/nlbwmon' /etc/sysupgrade.conf || echo '/opt/nlbwmon' >> /etc/sysupgrade.conf

# remove LuCI cache
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache

exit 0
